//需要配置自己QianDao.php运行时的url,然后需要QQ登录了的，因为使用的快速登录，如果有问题，请将
//var nightmare = Nightmare({ show: false,... }) 里的show: false,改成show: true看看是卡在哪一步了
var $url = 'http://localhost/PHP-qqQunQianDao/QianDao.php';//配置QianDao.php路径
var $groupId = '178633671,179866367';//配置群号，(多个群号以英文逗号分隔)可不填，不填则签到全部

/****************************
下面的代码一般情况下请不要改动
****************************/
var Nightmare = require('nightmare');
var nightmare = Nightmare({ show: false,webPreferences :{images : false} })
//show:是否显示脚本浏览器，开发选true;images关闭图像，省流量

var $uin;
var $skey;
nightmare
  .goto('https://qzone.qq.com/')
  .goto('https://xui.ptlogin2.qq.com/cgi-bin/xlogin?proxy_url=https%3A//qzs.qq.com/qzone/v6/portal/proxy.html&daid=5&&hide_title_bar=1&low_login=0&qlogin_auto_login=1&no_verifyimg=1&link_target=blank&appid=549000912&style=22&target=self&s_url=https%3A%2F%2Fqzs.qq.com%2Fqzone%2Fv5%2Floginsucc.html%3Fpara%3Dizone&pt_qr_app=手机QQ空间&pt_qr_link=https%3A//z.qzone.com/download.html&self_regurl=https%3A//qzs.qq.com/qzone/v6/reg/index.html&pt_qr_help_link=https%3A//z.qzone.com/download.html&pt_no_auth=0')
  .wait('#qlogin_list')
  .click('#qlogin_list a img')
  .wait("#QZ_Shop_Items_Container")
  .evaluate(function () {
    var cookie = document.cookie.match(/(uin)=(.+?);/g);
    var uin;
    cookie.forEach(function(e){
        if(uin != null)
            return;
         var index1 = e.indexOf("uin=");
         var index2 = e.indexOf(";");
        if(index1 == -1 || index2 <= 5){
            return;
        }else{
            uin = e.substring(4,index2);
        }
    })

    return uin;
  })
  .then(function (uin) {
    $uin = uin;
    nightmare
    .evaluate(function () {
        var cookie = document.cookie.match(/(skey)=(.+?);/g);
        var skey;
        cookie.forEach(function(e){
            if(skey != null)
                return;
             var index1 = e.indexOf("skey=@");
             var index2 = e.indexOf(";");
            if(index1 == -1 || index2 <= 5 || index2-5 >= 12){
                return;
            }else{
                skey = e.substring(5,index2);
            }
        })
        return skey;
      })
      .then(function (skey) {
        $skey = skey;
        nightmare
        .goto($url)
          .wait('#form')
          .insert('#uin',$uin)
          .insert('#skey',$skey)
          .insert('#groupId',$groupId)
          .click('#submit')
          .end()
          .catch(function (error) {
            console.error('Search failed:', error);
          });
      })
  })
